package sys

import (
	"strconv"
	"sync/atomic"
	"time"

	"github.com/shirou/gopsutil/v3/mem"

	"github.com/shirou/gopsutil/v3/cpu"
)

var (
	StartTime             = time.Now()
	Questions      uint64 = 0
	ThreadsCreated uint64 = 0
)

func Uptime() string {
	return time.Now().Sub(StartTime).String()
}

func QuestionIncrease() {
	atomic.AddUint64(&Questions, 1)
}

func ThreadsCreatedIncrease() {
	atomic.AddUint64(&ThreadsCreated, 1)
}

func CPUUsage() string {
	percent, _ := cpu.Percent(time.Second, false)
	return strconv.FormatFloat(percent[0], 'f', 2, 64) + "%"
}

func MemoryUsage() string {
	memInfo, _ := mem.VirtualMemory()
	return strconv.FormatFloat(memInfo.UsedPercent, 'f', 2, 64) + "%"
}
